I have modified the “LinesLables.efs” by adding a menu item in preMain() that allows me to change the name of the global variables. The idea is to allow me to have two of these scripts running in the same chart increasing the number of lines to 60 with each efs (30 lines) having a different ID tag for the global variables. (note: I have successfully increased the # of lines to 50 and above but prefer the above method because it allows more flexibility)
It works fine except that the global variables are not cleared when I change the ID tag (via Edit Studies) so other charts with different intervals that use the efs to draw lines reflect the old and new lines instead of just the new lines.
Placing “removeGlobalValue(xxx)” in postMain() doesn’t do the trick nor have I successfully added a removeGlobalValue(xxx) right after the "if (vLoaded == false) {" because I can't capture the old ID tags.
As I understand it, when I change anything via “Edit Studies” it reloads the efs but it doesn’t seem to trigger postMain().
Question:
How do I clear the old global variables when I change their unique ID via “Edit Studies”?
Thanks in advance.
Wayne
My version of LinesLables.efs is attached
It works fine except that the global variables are not cleared when I change the ID tag (via Edit Studies) so other charts with different intervals that use the efs to draw lines reflect the old and new lines instead of just the new lines.
Placing “removeGlobalValue(xxx)” in postMain() doesn’t do the trick nor have I successfully added a removeGlobalValue(xxx) right after the "if (vLoaded == false) {" because I can't capture the old ID tags.
As I understand it, when I change anything via “Edit Studies” it reloads the efs but it doesn’t seem to trigger postMain().
Question:
How do I clear the old global variables when I change their unique ID via “Edit Studies”?
Thanks in advance.
Wayne
My version of LinesLables.efs is attached
PHP Code:
/*****************************************************************
Provided By : eSignal. (c) Copyright 2003
Study: Lines and Labels
Version: 2.0
2.0 Updates - 12/18/2003
*Added FunctionParameter class for user inputs.
*Changed naming convention for the global variables
associated with vEditing to be symbol specific. This allows
the formula to be used with multiple sets of charts using
different symbols. Only charts with the same symbol will
share the same price levels for the lines.
*Added setShowTitleParameters(false) to hide formula parameters
from the study title.
*Added function parameter, Display Labels, to toggle the display
of the labels to ON/OFF.
*Added function parameter, Label Position, to set labels to appear
on the left side of the chart or to the right. If set to right,
the labels will appear on bar index 2 just right of the current bar.
*Added sharing of the main chart's formatting options for, Thickness,
Color, Display and Position.
Notes:
*Formula requires version 7.5.
*Draws up to 30 Horizontal Lines with optional labels.
*vEditing option allows the main chart where the price levels
for the lines are set to be shared with additional charts
using the same symbol. The additional charts only need to
have this formula running. The price levels only need to be set
once from the main chart. To enable this feature, set vEditing
to true in the main chart. After making subsequent changes in the
main chart, the other charts' LinesLabel
user changes 20090722: added a user defined ID for global variables-still
has bugs-previous globals are not cleared when the ID tag is changed
*****************************************************************/
var aFPArray = new Array();
function preMain() {
setPriceStudy(true);
setStudyTitle("Line & Labels MP Color-30var");
setShowTitleParameters(false);
var x=0;
aFPArray[x] = new FunctionParameter("vVAR", FunctionParameter.STRING);
with( aFPArray[x++] ) {
setName("Variable Label ID");
addOption("g");
addOption("h");
addOption("i");
addOption("j");
addOption("k");
setDefault("g");
}
aFPArray[x] = new FunctionParameter("vEditing", FunctionParameter.BOOLEAN);
with( aFPArray[x++] ) {
setName("vEditing (share lines w/ other charts)");
setDefault(false);
}
aFPArray[x] = new FunctionParameter("BandDisplay", FunctionParameter.STRING);
with( aFPArray[x++] ) {
setName("Display Bands");
addOption("ON");
addOption("OFF");
setDefault("ON");
}
aFPArray[x] = new FunctionParameter("LabelDisplay", FunctionParameter.STRING);
with( aFPArray[x++] ) {
setName("Display Labels");
addOption("ON");
addOption("OFF");
setDefault("ON");
}
aFPArray[x] = new FunctionParameter("bLDisplay", FunctionParameter.STRING);
with( aFPArray[x++] ) {
setName("Display Global Labels");
addOption("ON");
addOption("OFF");
setDefault("ON");
}
aFPArray[x] = new FunctionParameter("sLabelPos", FunctionParameter.STRING);
with( aFPArray[x++] ) {
setName("Label Position");
addOption("Left");
addOption("Right");
setDefault("Left");
}
aFPArray[x] = new FunctionParameter("LLabelOffset", FunctionParameter.NUMBER);
with( aFPArray[x++] ) {
setName("Left Label Offset");
setLowerLimit(0);
setUpperLimit(20);
addOption(0);
setDefault(0);
}
aFPArray[x] = new FunctionParameter("RLabelOffset", FunctionParameter.NUMBER);
with( aFPArray[x++] ) {
setName("Right Label Offset");
setLowerLimit(0);
setUpperLimit(40);
addOption(10);
setDefault(10);
}
aFPArray[x] = new FunctionParameter( "ShowCursorLabel", FunctionParameter.BOOLEAN);
with( aFPArray[x++] ) {
setName( "Show Cursor Label" );
setDefault( false );
}
var afp1 = new Array(31);
afp1[0] = "";
var afp2 = new Array(31);
afp2[0] = "";
var afp3 = new Array(31);
afp3[0] = "";
var afp4 = new Array(31);
afp4[0] = "";
var i = 1;
for (i = 1; i < 31; ++i) {
var L = "L"+i;
afp1[i] = new FunctionParameter(L, FunctionParameter.NUMBER);
afp1[i].setName("Line " + i);
var Ll = "L"+i+"label";
afp2[i] = new FunctionParameter(Ll, FunctionParameter.STRING);
afp2[i].setName("Line " + i + " Label");
afp2[i].setDefault(" ");
var C = "L"+i+"color";
afp3[i] = new FunctionParameter(C, FunctionParameter.COLOR);
afp3[i].setName("Line " + i + " Color");
afp3[i].setDefault(Color.blue);
var T = "L"+i+"thickness";
afp4[i] = new FunctionParameter(T, FunctionParameter.NUMBER);
afp4[i].setName("Line " + i + " Thickness");
afp4[i].setLowerLimit( 1 );
afp4[i].setUpperLimit( 5 );
afp4[i].addOption( 1 );
afp4[i].addOption( 2 );
afp4[i].addOption( 3 );
afp4[i].addOption( 4 );
afp4[i].addOption( 5 );
afp4[i].setDefault( 2 );
}
}
var vLoaded = false;
var vEdit = null;
var vSym = null;
var bGlobals = false;
var vThi = null;
var vCol = null;
var vDis = null;
var vPos = null;
debugClear();
var vtxt = -1;
var vVarGlobal = null;
function main(vVAR,vEditing,ShowCursorLabel,BandDisplay,LabelDisplay,bLDisplay,sLabelPos,LLabelOffset,RLabelOffset,
L1, L1label, L1color, L1thickness, L2, L2label, L2color, L2thickness, L3,
L3label, L3color, L3thickness, L4, L4label, L4color, L4thickness, L5, L5label,
L5color, L5thickness, L6, L6label, L6color, L6thickness, L7, L7label, L7color,
L7thickness, L8, L8label, L8color, L8thickness, L9, L9label, L9color, L9thickness,
L10, L10label, L10color, L10thickness, L11, L11label, L11color, L11thickness, L12,
L12label, L12color, L12thickness, L13, L13label, L13color, L13thickness, L14, L14label,
L14color, L14thickness, L15, L15label, L15color, L15thickness, L16, L16label, L16color,
L16thickness, L17, L17label, L17color, L17thickness, L18, L18label, L18color,
L18thickness, L19, L19label, L19color, L19thickness, L20, L20label, L20color,
L20thickness, L21, L21label, L21color, L21thickness, L22, L22label, L22color,
L22thickness, L23, L23label, L23color, L23thickness, L24, L24label, L24color,
L24thickness, L25, L25label, L25color, L25thickness, L26, L26label, L26color,
L26thickness, L27, L27label, L27color, L27thickness, L28, L28label, L28color,
L28thickness, L29, L29label, L29color, L29thickness, L30, L30label, L30color,
L30thickness) {
var sTextFlags = null;
var nTextX = 0;
setShowCursorLabel(ShowCursorLabel);
if (vSym == null) vSym = getSymbol();
if (vLoaded == false) {
for (i = 1; i <= 30; ++i) {
var vDataLabel = "L" + i + "label";
removeText(vDataLabel);
removeBand(vDataLabel);
removeGlobalValue(vSym + vVarGlobal + "L"+i);
removeGlobalValue(vSym + vVarGlobal + "L"+i+"label");
removeGlobalValue(vSym + vVarGlobal + "L"+i+"color");
removeGlobalValue(vSym + vVarGlobal + "L"+i+"thickness");
}
vVarGlobal = vVAR;
if (vEditing == true) {
vEdit = true;
} else if (vEditing == false) {
vEdit = false;
} else {
vEdit = false;
}
if (vEdit == true) { // share formatting options
setGlobalValue(vSym + vVAR + "LDisplay", bLDisplay);
setGlobalValue(vSym + vVAR + "LabelPos", sLabelPos);
}
for (i = 1; i <= 30; ++i) {
var vData = "L" + i;
var vDataLabel = "L" + i + "label";
var vLabelColor = "L" + i + "color";
var vLabelThickness = "L" + i + "thickness";
var gData = getGlobalValue(vSym + vVAR + vData);
var gDataLabel = getGlobalValue(vSym + vVAR + vDataLabel);
var gLabelColor = getGlobalValue(vSym + vVAR + vLabelColor);
var gLabelThickness = getGlobalValue(vSym + vVAR + vLabelThickness);
if (eval(vData) != null) {
if (vEdit == true) { // Current Chart is sharing inputs.
setGlobalValue(vSym + vVAR + "L"+i, eval(vData));
if (eval(vDataLabel) == null) {
setGlobalValue(vSym + vVAR + "L"+i+"label", "null");
} else {
setGlobalValue(vSym + vVAR + "L"+i+"label", eval(vDataLabel));
}
if (eval(vLabelColor) == null) {
setGlobalValue(vSym + vVAR + "L"+i+"color", "null");
} else {
setGlobalValue(vSym + vVAR + "L"+i+"color", eval(vLabelColor));
}
if (eval(vLabelThickness) == null) {
setGlobalValue(vSym + vVAR + "L"+i+"thickness", "null");
} else {
setGlobalValue(vSym + vVAR + "L"+i+"thickness", eval(vLabelThickness));
}
}
if(BandDisplay == "ON") addBand(eval(vData), PS_SOLID, eval(vLabelThickness), eval(vLabelColor), vDataLabel);
if (bLDisplay == "ON") {
if (sLabelPos == "Right") {
sTextFlags = "Text.LEFT|Text.ONTOP|Text.VCENTER|Text.Bold|Text.FRAME";
nTextX = RLabelOffset;
} else {
sTextFlags = "Text.RELATIVETOLEFT|Text.ONTOP|Text.VCENTER|Text.Bold|Text.FRAME";
nTextX = LLabelOffset;
}
if(LabelDisplay == "ON") drawTextAbsolute(nTextX, eval(vData), " " + eval(vDataLabel) + " ",
Color.white, eval(vLabelColor), eval(sTextFlags), null, 10, vDataLabel);
}
} else if (vEdit == true) {
removeText(vDataLabel);
removeBand(vDataLabel);
removeGlobalValue(vSym + vVAR + "L"+i);
removeGlobalValue(vSym + vVAR + "L"+i+"label");
removeGlobalValue(vSym + vVAR + "L"+i+"color");
removeGlobalValue(vSym + vVAR + "L"+i+"thickness");
}
// Current chart is not sharing but another chart is.
if (vEdit == false && eval(vData) == null && getGlobalValue(vSym + vVAR + "L"+i) != null) {
if (bGlobals == false) {
vDis = getGlobalValue(vSym + vVAR + "LDisplay");
if (vDis == null) vDis = bLDisplay;
vPos = getGlobalValue(vSym + vVAR + "LabelPos");
if (vPos == null) vPos = sLabelPos;
bGlobals = true;
}
// addBand(gData, PS_SOLID, vThi, vCol, gDataLabel);
if(BandDisplay == "ON") addBand(gData, PS_SOLID, gLabelThickness, gLabelColor, gDataLabel);
if (vDis == "ON") {
if (vPos == "Right") {
sTextFlags = "Text.LEFT|Text.ONTOP|Text.VCENTER|Text.Bold|Text.FRAME";
nTextX = 2;
} else {
sTextFlags = "Text.RELATIVETOLEFT|Text.ONTOP|Text.VCENTER|Text.Bold|Text.FRAME";
nTextX = 0;
}
if(LabelDisplay == "ON") drawTextAbsolute(nTextX, gData, " " + gDataLabel + " ", Color.white,
gLabelColor, eval(sTextFlags), null, 10, vDataLabel);
}
}
}
vLoaded = true;
}
return;
}
/*function postMain(){
for (i = 1; i <= 30; ++i) {
// if(vEdit == false){//true){//reloadEFS()
var vDataLabel = "L" + i + "label";
// removeText(vDataLabel);//only used in main()
removeBand(vDataLabel);
removeGlobalValue(vSym + vVarGlobal + "L"+i);
removeGlobalValue(vSym + vVarGlobal + "L"+i+"label");
removeGlobalValue(vSym + vVarGlobal + "L"+i+"color");
removeGlobalValue(vSym + vVarGlobal + "L"+i+"thickness");
// }
}
}*/
Comment